<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>User's Action View</title>
<link type="text/css" href="JSP/css/style.css" rel="stylesheet"></link>
</head>
<%@include file="../checkSession.jsp"%>
<%@page import="java.util.LinkedList"%>
<%@page import="model.Table"%>
<%@page import="model.ActionLog"%>
<%@page import="model.LoginLog"%>
<%!LinkedList<Table> list1;
	LinkedList<String> list;
	LinkedList<ActionLog> listRS;
	LinkedList<LoginLog> listRS1;
	String user;
	String owner;
	String statType;%>
<%
	list = (LinkedList<String>) request.getAttribute("lstUser");
	list1 = (LinkedList<Table>) request.getAttribute("lstTable");
	listRS = (LinkedList<ActionLog>) request.getAttribute("lstDML");
	listRS1 = (LinkedList<LoginLog>) request.getAttribute("lstDDL");
	user = (String) request.getAttribute("grantee");
	owner=(String) request.getAttribute("owner");
	statType=(String)request.getAttribute("stat");
	if (list == null) {
		out.println("NULL");
	} else {

		for (int i = 0; i < list.size(); i++) {
			String s = list.get(i);
			if (s.equalsIgnoreCase(user)) {
				list.remove(i);
				list.addFirst(user);
				break;
			}

		}
	
		if (owner!= null && list1!=null) {
			 
			for (int i = 0; i < list1.size(); i++) {
				Table t = list1.get(i);
				if (t.ownerName.equalsIgnoreCase(owner)) {
					list1.remove(i);
					list1.addFirst(t);
					break;
				}

			}	
		}
%>
<body>

	<div id="wrap">
		<%@include file="adminHeader.jsp"%>
		<font size="3" face="verdana" color="orange">Users's Actions</font>
		<div class="center_content">
			<%@include file="auditingLeftContent.jsp"%>
			<div class="right_content">
				<form action=<%="./SubmitViewUserAudit?grantee=" + user%>
					method="post">
					<table border=0>
						<tr>
							<td>User</td>
							<td></td>
							<td><select name="User"
								onchange="window.location.href=this.value">
									<%
										String u;
											for (int i = 0; i < list.size(); i++) {
												u = list.get(i);
									%>
									<option value=<%="./ViewUserAudit?grantee=" + u%>><%=u%></option>
									<%
										}
									%>
							</select></td>
						</tr>
						<tr>
							<td>Object</td>
							<td></td>
							<td><select name="Table">
									<%
										for (int i = 0; i < list1.size(); i++) {
												Table t = list1.get(i);
									%>
									<option value=<%=t.ownerName%>><%=t.ownerName + "." + t.tableName%></option>
									<%
										}
									%>
							</select></td>
						</tr>
						<tr>
							<td>Statement</td>
							<td></td>
							<td><select name="stateType">
							<%String s1="",s2="",s3="",s4="",s5="",s6="",s7="";
							if("SELECT".equalsIgnoreCase(statType))s1="selected";
							else if("insert".equalsIgnoreCase(statType))s2="selected";
							else if("update".equalsIgnoreCase(statType))s3="selected";
							else if("delete".equalsIgnoreCase(statType))s4="selected";
							else if("all".equalsIgnoreCase(statType))s5="selected";
							else if("password".equalsIgnoreCase(statType))s6="selected";
							else if("log".equalsIgnoreCase(statType))s7="selected";%>
									<option value="SELECT" <%=s1 %>>SELECT</option>
									<option value="INSERT" <%=s2 %>>INSERT</option>
									<option value="UPDATE" <%=s3 %>>UPDATE</option>
									<option value="DELETE" <%=s4 %>>DELETE</option>
									<option value="ALL" <%=s5 %>>ALL DML</option>
									<option value="PASSWORD" <%=s6 %>>PASSWORD CHANGE</option>
									<option value="LOG" <%=s7 %>>LOGIN - LOGOUT</option>

							</select></td>
						</tr>
						<tr>
							<td><input type=submit name=confirm value="Confirm" /></td>
							<td></td>
							<td></td>
						</tr>
					</table>
				</form>
				<%
					if (listRS != null) {
				%>
				<table border=1>
					<tr>
						<th class="table-header-repeat line-left minwidth-1">Object</th>
						<th class="table-header-repeat line-left minwidth-1">Action</th>
						<th class="table-header-repeat line-left">Time</th>
						<th class="table-header-repeat line-left" style="width: 200px;">SQLStatement</th>
					</tr>
					<%
						if (listRS != null) {

									for (int i = 0; i < listRS.size(); i++) {
										ActionLog a = listRS.get(i);
					%>
					<tr>
						<td><%=a.ownerObj + "." + a.object%></td>
						<td><%=a.action%></td>
						<td><%=a.time%></td>
						<td><%=a.sqlStat%></td>
					</tr>

					<%
						}

								}
					%>
				</table>
				<%
					}
				%>
				<%
					if (listRS1 != null) {
							LoginLog l = listRS1.get(0);
				%>
				<table border=1>
					<tr>
						<%
							if (!"ALTER USER".equals(l.field2)) {
						%>
						<th class="table-header-repeat line-left minwidth-1">Time
							Login</th>
						<th class="table-header-repeat line-left">Time Logout</th>
						<%
							} else {
						%>
						<th class="table-header-repeat line-left minwidth-1">Changing
							Password Time</th>
						<%
							}
						%>
					</tr>
					<%
						if (listRS1 != null) {
									for (int i = 0; i < listRS1.size(); i++) {
										l = listRS1.get(i);
					%>
					<tr>

						<td><%=l.field1%></td>
						<%
							if (l.field2 != "ALTER USER") {
						%>
						<td><%=l.field2%></td>
						<%							}
						%>
					</tr>
					<%
						}
								}
					%>
				</table>
				<%
					}
					else{
						if(listRS == null){
						%>
						<font color="black">0 row is selected.</font>
						<%
						}
					}
					}
				%>

			</div>
		</div>
	</div>
</body>
</html>